package springProvider.controller;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.math.RandomUtils;
//import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import springProvider.model.Person;

@RestController
@RequestMapping("/provide")
public class FirstController {
	@RequestMapping("/person/{name}")
	public Person getPerson(@PathVariable String name,int age,HttpServletRequest request) throws InterruptedException {
		Person person = new Person(name,age);
		person.setMessage(request.getRequestURL().toString());
		 return person;
	} 
	
	@RequestMapping(value="/persons")
	public List<Person> getPersons(String[] names,HttpServletRequest request) throws InterruptedException {
		if(names!=null) {
			return Arrays.stream(names).filter(s->{return s!=null;}).map(s->{return new Person(s, RandomUtils.nextInt());}).collect(Collectors.toList());
		}
		return null;
	} 
	
//	@Inject
//	private JdbcTemplate jdbcTemplate;
//	
//	@RequestMapping(value="/testjdbc")
//	public String testjdbc() throws InterruptedException {
//		return "jdbc template is null:"+(jdbcTemplate==null);
//	} 
}
